import { reqGoodsInfo,reqCart } from "@/api"
import { getUUID } from "@/utils/index"
const mutations={
    GETGOODINFO(state,goodInfo){
     state.goodInfo=goodInfo
    } 
}
const state={
    goodInfo:{},
    uuid:getUUID()
}
const actions={
     async getGoodInfo(context,id){
        let results =await reqGoodsInfo(id)
        if(results.code===200){
            context.commit("GETGOODINFO",results.data)
        }

    },
    async getCart(context,{id,skuNum}){
        let results =await reqCart(id,skuNum)
        if(results.code===200){
            return 'ok'
        }else{
            return Promise.reject(new Error('faile'))
        }

    }
}
const getters={
    categoryView(state){
        return state.goodInfo.categoryView||{}
    },
    skuInfo(state){
        return state.goodInfo.skuInfo||{}
    },
    spuSaleAttrList(state){
        return state.goodInfo.spuSaleAttrList||[]
    }
}
export default{
    mutations,
    state,
    actions,
    getters
}